<?php

use app\store\model\store\shop\CardOrder;

?>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf"><?= $title ?></div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form id="form-search" class="toolbar-form" action="">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <input type="hidden" name="dataType" value="<?= $dataType ?>">
                            <div class="am-u-sm-12 am-u-md-3">
                                <!--<div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <?php /*if (checkPrivilege('order.operate/export')): */?>
                                                <a class="j-export am-btn am-btn-success am-radius"
                                                   href="javascript:void(0);">
                                                    <i class="iconfont icon-daochu am-margin-right-xs"></i>订单导出
                                                </a>
                                            <?php /*endif; */?>
                                            <?php /*if (checkPrivilege('order.operate/batchdelivery')): */?>
                                                <?php /*if (in_array($dataType, ['all', 'delivery'])): */?>
                                                    <a class="j-export am-btn am-btn-secondary am-radius"
                                                       href="<?/*= url('order.operate/batchdelivery') */?>">
                                                        <i class="iconfont icon-daoru am-margin-right-xs"></i>批量发货
                                                    </a>
                                                <?php /*endif; */?>
                                            <?php /*endif; */?>
                                        </div>
                                    </div>
                                </div>-->
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <?php $order_status = $request->get('order_status'); ?>
                                        <select name="order_status"
                                                data-am-selected="{btnSize: 'sm', placeholder: '订单状态'}">
                                            <option value=""></option>
                                            <option value="0"
                                                <?= $order_status === '0' ? 'selected' : '' ?>>全部
                                            </option>
                                            <?php foreach (CardOrder::datas() as $item): ?>
                                                <option value="<?= $item['value'] ?>"
                                                    <?= $item['value'] == $order_status ? 'selected' : '' ?>><?= $item['name'] ?>
                                                </option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="start_time"
                                               class="am-form-field"
                                               value="<?= $request->get('start_time') ?>" placeholder="请选择付款起始日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="end_time"
                                               class="am-form-field"
                                               value="<?= $request->get('end_time') ?>" placeholder="请选择付款截止日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入订单号/预约人姓名" value="<?= $request->get('search') ?>">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search"
                                                        type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="am-scrollable-horizontal am-u-sm-11">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>卡座订单ID</th>
                                <th>卡座名称</th>
                                <th>卡座描述</th>
                                <th width="15%">订单号</th>
                                <th>预约人姓名</th>
                                <th>手机号</th>
                                <th>预约时间</th>
                                <th>是否支付</th>
                                <th>订单状态</th>
                                <th>付款时间</th>
                                <th>核销二维码</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $order): ?>
                                <tr class="order-empty">
                                    <td class="am-text-middle"><?= $order['id']?></td>
                                    <td class="am-text-middle"><?= $order['real_name']?></td>
                                    <td class="am-text-middle"><?= $order['phone']?></td>
                                    <td class="am-text-middle"><?= $order['order_no']?></td>
                                    <td class="am-text-middle"><?= $order['subscribe_name']?></td>
                                    <td class="am-text-middle"><?= $order['mobile']?></td>
                                    <td class="am-text-middle"><?= $order['appointment_time']?></td>
                                    <td class="am-text-middle">
                                        <span class="am-badge am-badge-<?= $order['is_pay'] ? 'success' : 'warning' ?>">
                                           <?= $order['is_pay'] ? '已付' : '未付' ?>
                                       </span>
                                    </td>
                                    <td class="am-text-middle">
                                        <?php if($order['order_status']==1){
                                            echo '审核中';
                                         }elseif($order['order_status']==2){
                                        echo '待核销';
                                        }elseif($order['order_status']==3){
                                            echo'已完成';
                                        }?>
                                    </td>
                                    <td class="am-text-middle"><?= date('Y-m-d H:i:s',$order['pay_time'])?></td>
                                    <td class="am-text-middle">
                                        <a href="<?= $order['qrcode_url'] ?>" title="点击查看大图" target="_blank">
                                            <img src="<?= $order['qrcode_url'] ?>" width="72" height="72" alt="">
                                        </a>
                                    </td>
                                    <td class="am-text-middle">
                                        <?php if($order['order_status']==1){ ?>
                                            <a href="javascript:void(0);" class="item-delete" data-id="<?= $order['id']?>>
                                                <i class="am-icon-pencil"></i> 审核
                                            </a>
                                        <?php } ?>
                                    </td>
                                </tr>

                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="10" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    $(function () {

        /**
         * 订单导出
         */
        $('.j-export').click(function () {
            var data = {};
            var formData = $('#form-search').serializeArray();
            $.each(formData, function () {
                this.name !== 's' && (data[this.name] = this.value);
            });
            window.location = "<?= url('order.operate/export') ?>" + '&' + $.urlEncode(data);
        });
        // 审核元素
        var url = "<?= url('shop.card/examine') ?>";
        $('.item-delete').click(function () {
            var param = {};
            param['id'] = $(this).attr('data-id');
            $.post(url, param, function (result) {
                result.code === 1 ? $.show_success(result.msg, result.url)
                    : $.show_error(result.msg);
            });
            layer.close(index);
        });
    });


</script>

